package com.yjh.admin.controller.chronic;



import com.yjh.admin.dto.chronic.AbnormalStatisticsDto;
import com.yjh.admin.dto.chronic.WarningTrendDto;
import com.yjh.admin.server.chronic.StatisticsService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import util.DateUtil;
import util.R;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 体征统计
 *
 * @author GuoBin
 * @date 2020-08-14 16:51:45
 */
@ApiOperation("统计")
@RestController
@AllArgsConstructor
@RequestMapping("/statistics")
public class StatisticsController {



    @Autowired
    private StatisticsService statisticsService;


    @ApiOperation("健康报告")
    @GetMapping("/physicalSignsStatistics")
    public R physicalSignsStatistics() {
        List<Object>  list = new ArrayList<>();

//		List<String> date = new ArrayList<>();
//		SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
//
//
//		//获取上个月每周的时间
//		Calendar cal = Calendar.getInstance();
//		int year = cal.get(Calendar.YEAR);
//		cal.add(Calendar.MONTH, -1);//上个月时间
//		cal.set(Calendar.DAY_OF_MONTH,1);
//		String sBeginTime = time.format(cal.getTime());
//
//
//		int month = cal.get(Calendar.MONTH)-1;
//
//		for (int i = 1; i < 32; i++) {
//			if(i/7==0){
//				sBeginTime=time.format(cal.getTime());
//				cal.set(Calendar.DAY_OF_MONTH,+7);
//				date.add(sBeginTime+"-"+time.format(cal.getTime()));
//			}
//		}
        return new R<>();
    }



    @ApiOperation("异常预警统计")
    @GetMapping("/abnormalStatistics")
    public R<AbnormalStatisticsDto> abnormalStatistics() {
        return new R<>(statisticsService.abnormalStatistics());
    }



    @ApiOperation("预警趋势(近七天数据)")
    @GetMapping("/queryWarningTrend")
    public R<WarningTrendDto> queryWarningTrend(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        //往后推7天
        Date date = DateUtil.getDate(-7);
        return new R<>(statisticsService.queryWarningTrend(format.format(date),format.format(new Date())));
    }


}
